package org.xlh.springboot.component;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {

    //定义日志对象
    private static final Logger log = LoggerFactory.getLogger(LoggingAspect.class);

    //定义切入点
    @Pointcut("execution(* org.xlh.springboot.service..*(..))")
    public void serviceMethods(){
    }

    //定义前置通知
    @Before("serviceMethods()")
    public void logBefore(JoinPoint joinPoint){
        String methodName = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        log.info("调用方法:{}，参数：{}", methodName, args);
    }
}
